package com.halfsword.creativecraft;

import com.halfsword.creativecraft.block.BlockLoader;
import com.halfsword.creativecraft.block.custom.machine.blockentity.TileEntities;
import com.halfsword.creativecraft.creativetab.CreativeTabLoader;
import com.halfsword.creativecraft.entity.Entities;
import com.halfsword.creativecraft.entity.client.NothingRender;
import com.halfsword.creativecraft.entity.villager.Villagers;
import com.halfsword.creativecraft.gui.MenuTypes;
import com.halfsword.creativecraft.gui.machine.SpaceCollectorScreened;
//import com.halfsword.creativecraft.integration.top.SpaceCollectorProbe;
import com.halfsword.creativecraft.gui.machine.SteamCrusherScreened;
import com.halfsword.creativecraft.item.ItemLoader;
import com.halfsword.creativecraft.loot.LootModifiers;
import com.halfsword.creativecraft.recipe.RecipeLoader;
import com.halfsword.creativecraft.sound.Sounds;
import com.mojang.logging.LogUtils;
//import mcjty.theoneprobe.api.IProbeInfoProvider;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.client.renderer.entity.EntityRenderers;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FlowerPotBlock;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.slf4j.Logger;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(CreativeCraft.MOD_ID)
public class CreativeCraft
{
    // Define mod id in a common place for everything to reference
    public static final String MOD_ID = "creativecraft";
    // Directly reference a slf4j logger
    public static final Logger LOGGER = LogUtils.getLogger();
    public CreativeCraft(FMLJavaModLoadingContext context)
    {
        IEventBus modEventBus = context.getModEventBus();


        ItemLoader.register(modEventBus);
        BlockLoader.register(modEventBus);
        CreativeTabLoader.register(modEventBus);
        LootModifiers.register(modEventBus);
        Villagers.register(modEventBus);
        Sounds.register(modEventBus);
        Entities.register(modEventBus);
        TileEntities.register(modEventBus);
        MenuTypes.register(modEventBus);
        RecipeLoader.register(modEventBus);

        modEventBus.addListener(this::commonSetup);



        MinecraftForge.EVENT_BUS.register(this);


        modEventBus.addListener(this::addCreative);


    }

    private void commonSetup(final FMLCommonSetupEvent event) {
        event.enqueueWork(() ->{
            ((FlowerPotBlock) Blocks.FLOWER_POT).addPlant(BlockLoader.CALENDULA.getId(),BlockLoader.POTTED_CALENDULA);
//            InterModComms.sendTo("theoneprobe", "getTheOneProbe", ::new);

        });

    }


    private void addCreative(BuildCreativeModeTabContentsEvent event)
    {
        if(event.getTabKey() == CreativeModeTabs.INGREDIENTS) {
            event.accept(ItemLoader.GEMSPACE);
            event.accept(ItemLoader.RAWSPACE);
        }

    }


    @SubscribeEvent
    public void onServerStarting(ServerStartingEvent event)
    {

    }


    @Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
    public static class ClientModEvents
    {
        @SubscribeEvent
        public static void onClientSetup(FMLClientSetupEvent event)
        {
            EntityRenderers.register(Entities.NOTHING.get(), NothingRender::new);




            MenuScreens.register(MenuTypes.SPACE_COLLECTOR_MENU.get(), SpaceCollectorScreened::new);
            MenuScreens.register(MenuTypes.STEAM_CRUSHER_MENU.get(), SteamCrusherScreened::new);

        }
    }
}
